<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>java的架构师技术栈</title>
    <script type="text/javascript">
        var socket;
        if (!window.WebSocket) {
            window.WebSocket = window.MozWebSocket;
        }
        if (window.WebSocket) {
            socket = new WebSocket("ws://120.26.196.82:9002/ws");
            socket.onmessage = function (event) {
                var ta = document.getElementById('responseText');
                ta.value += event.data + "\r\n";
            };
            socket.onopen = function (event) {
                var ta = document.getElementById('responseText');
                ta.value = "已连接";
            };
            socket.onclose = function (event) {
                var ta = document.getElementById('responseText');
                ta.value = "已关闭";
            };
        } else {
            alert("您的浏览器不支持WebSocket协议！");
        }

        function send(message) {
            if (!window.WebSocket) {
                return;
            }
            if (socket.readyState == WebSocket.OPEN) {
                var head = {
                    'token': '1694623553549336576'
                }
                var body = {
                    'userCode': message,
                    'subscription': ['BTCUSD', 'MARKETS']
                }
                var o = {
                    'bizCode': 'C10000',
                    'head': JSON.stringify(head),
                    'body': JSON.stringify(body),
                }
                socket.send(JSON.stringify(o));
            } else {
                alert("WebSocket 连接没有建立成功！");
            }
        }
    </script>
</head>
<body>
<form onsubmit="return false;">
    <hr color="black"/>
    <h3>客户端发送的信息</h3>
    <label>名字</label>
    <input type="text" name="uid" value="Java 求学之路"/>
    <br/>
    <label>内容</label>
    <input type="text" name="message" value="hello 我是菜鸟"/>
    <br/>
    <br/>
    <input type="button" value="初始化-token上报" onclick="send(this.form.uid.value+':'+this.form.message.value)"/>
    <input type="button" value="点击发送" onclick="send(this.form.message.value)"/>
    <hr color="black"/>
    <h3>服务端返回的应答消息</h3>
    <textarea id="responseText" style="width: 900px;height: 300px;"></textarea>
</form>
</body>
</html>